package com.cbd.basic.leetcode.easy;

import lombok.extern.slf4j.Slf4j;

/**
 * 两个字符串相加
 * ASCII码 0对应48，a对应97，A对应65
 */
@Slf4j
public class Solution415 {
    public static void main(String[] args) {
        String result = addStrings("4568", "79");
        log.info("result = {}", result);
    }

    public static String addStrings(String num1, String num2) {
        int i = num1.length() - 1;
        int j = num2.length() - 1;
        int k = 0;
        StringBuilder stringBuilder = new StringBuilder();
        while (i >= 0 || j >= 0 || k > 0) {
            int a = i >= 0 ? num1.charAt(i) - '0' : 0;
            int b = j >= 0 ? num2.charAt(j) - '0' : 0;
            int result = a + b + k;
            stringBuilder.append(result % 10);
            k = result / 10;
            i --;
            j --;
        }
        return stringBuilder.reverse().toString();
    }
}
